<?php

namespace app\api\controller;

class Article extends ApiBase
{

    /**
     * 资讯列表
     * page     页码
     */
    public function articleList()
    {
        $page = input('page', 1);
        $list = model('Article')->getArticleList('资讯', $page - 1);
        $data = [];
        if(empty($list)){
            $this->ajaxReturn($data, 0, '没有数据了');
        } else {
            foreach($list as $k => $v){
                $data[$k] = [
                    'id'            => $v['article_id'],
                    'title'         => $v['title'],
                    'add_time'      => date('Y-m-d H:i:s', $v['add_time']),
                    'img'           => SITE_URL . $v['thumb'],
                    'link'          => $v['link']
                ];
            }
            $this->ajaxReturn($data);
        }
    }

    /**
     * 资讯详情
     * id
     */
    public function articleDetail()
    {
        $id = input('id', 0);
        $data = model('Article')->where('article_id', $id)->find();
        if(empty($data)){
            $this->ajaxReturn($data, 0, '没有数据了');
        } else {
            $data['add_time'] = date('Y-m-d H:i:s', $data['add_time']);
            $data['thumb'] = SITE_URL . $data['thumb'];
            $data['content'] = htmlspecialchars_decode(str_replace('/public/upload/article', SITE_URL . '/public/upload/article', $data['content']));
            $this->ajaxReturn($data);
        }

    }


}